package com.ywz.project.system.service.impl;

import com.ywz.common.ResultResp;
import com.ywz.common.TreeListUtils;
import com.ywz.project.base.system.entity.TChina;
import com.ywz.project.base.system.service.TChinaService;
import com.ywz.project.system.service.ChinaApiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
public class ChinaApiServiceImpl implements ChinaApiService {
    @Resource
    private TChinaService tChinaService;

    @Override
    public ResultResp getList() {
        return ResultResp.success(tChinaService.list());
    }

    @Override
    public ResultResp getTreeListById(Integer id) {
        if (id == null) id = 0;
        List<TChina> tChains = TreeListUtils.listToTree(tChinaService.list(), TChina.class, "id", "pid", id, "children");
        return ResultResp.success(tChains);
    }
}
